package com.ruoyi.business.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.business.domain.ShopComments;
import com.ruoyi.business.domain.ShopCommentsDto;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.business.mapper.ShopCommentsMapper;
import com.ruoyi.business.service.ShopCommentsService;

/**

 * 商铺评论Service业务层处理

 *

 * @author ruoyi

 * @date 2025-06-09
 */
@Service
public class ShopCommentsServiceImpl implements ShopCommentsService
{
    @Autowired
    private ShopCommentsMapper tbShopCommentsMapper;

    /**

     * 查询商铺评论
     *
     * @param id 商铺评论主键
     * @return 商铺评论
     */
    @Override
    public ShopComments selectTbShopCommentsById(String id)
    {
        return tbShopCommentsMapper.selectTbShopCommentsById(id);
    }

    /**

     * 查询商铺评论列表
     *
     * @param shopComments 商铺评论
     * @return 商铺评论
     */
    @Override
    public List<ShopCommentsDto> selectTbShopCommentsList(ShopComments shopComments)
    {
        List<ShopCommentsDto> listDto = new ArrayList<>();
        List<ShopComments> list = tbShopCommentsMapper.selectTbShopCommentsList(shopComments);
        for(ShopComments shopCommentsOne : list){
            ShopCommentsDto tbShopCommentsDto = new ShopCommentsDto();
            String  userId = shopCommentsOne.getUserId();
            String  nickName = tbShopCommentsMapper.selectTbUserNickNameById(userId);
            tbShopCommentsDto.setNickName(nickName);
            tbShopCommentsDto.setId(shopCommentsOne.getId());
            tbShopCommentsDto.setUserId(shopCommentsOne.getUserId());
            tbShopCommentsDto.setShopId(shopCommentsOne.getShopId());
            tbShopCommentsDto.setContent(shopCommentsOne.getContent());
            tbShopCommentsDto.setScore(shopCommentsOne.getScore());
            tbShopCommentsDto.setCreateTime(shopCommentsOne.getCreateTime());
            tbShopCommentsDto.setUpdateTime(shopCommentsOne.getUpdateTime());
            tbShopCommentsDto.setStatus(shopCommentsOne.getStatus());
            tbShopCommentsDto.setIsDeleted(shopCommentsOne.getIsDeleted());
            listDto.add(tbShopCommentsDto);
        }
        return listDto;
    }

    /**

     * 新增商铺评论
     *
     * @param shopComments 商铺评论
     * @return 结果
     */
    @Override
    public int insertTbShopComments(ShopComments shopComments)
    {
        shopComments.setCreateTime(DateUtils.getNowDate());
        return tbShopCommentsMapper.insertTbShopComments(shopComments);
    }

    /**

     * 修改商铺评论
     *
     * @param shopComments 商铺评论
     * @return 结果
     */
    @Override
    public int updateTbShopComments(ShopComments shopComments)
    {
        shopComments.setUpdateTime(DateUtils.getNowDate());
        return tbShopCommentsMapper.updateTbShopComments(shopComments);
    }

    /**

     * 批量删除商铺评论
     *
     * @param ids 需要删除的商铺评论主键
     * @return 结果
     */
    @Override
    public int deleteTbShopCommentsByIds(Long[] ids)
    {
        return tbShopCommentsMapper.deleteTbShopCommentsByIds(ids);
    }

    /**

     * 删除商铺评论信息
     *
     * @param id 商铺评论主键
     * @return 结果
     */
    @Override
    public int deleteTbShopCommentsById(String id)
    {
        return tbShopCommentsMapper.deleteTbShopCommentsById(id);
    }
}